

$(document).ready(function(){
	
	//window.addEventListener('deviceorientation', Game.onDeviceOrientation);
	window.addEventListener('devicemotion', Game.onDeviceMotion);
	
	Game.drinkerId = $.cookie('drinkerId');
	
	if($(document.body).attr('id') == 'play')
	{
		if(Game.drinkerId)
		{
			console.log(Game.drinkerId);
			Game.init();
			myTeaboySocket = pusher.subscribe('teaboyUser'+Game.drinkerId);
		}
	}
	
	teaboySocket.bind('newGame', function(thing) {
		Game.onNewGameEvent();
	});
	
	teaboySocket.bind('countdown', function(thing) {
		Game.onCountDownEvent(thing.seconds);
	});
	
	teaboySocket.bind('start', function(thing) {
		Game.onStartGameEvent(thing.gameId);
	});
	
	teaboySocket.bind('gameOver', function(thing) {
		Game.onEndGameEvent();
	});
	
	if(myTeaboySocket)
	{
		myTeaboySocket.bind('status', function(thing) {
			Game.onResultEvent(thing.result, thing.players);
		});	
	}
	
});
